Skip to content

Conversation

@mattia1208
Copy link
Contributor

@mattia1208 mattia1208 commented Nov 7, 2025

Pull Request

Issue

https://github.com/parse-community/parse-server/issues/9907

The issue occurs because the mapperFor function in buildConfigDefinitions.js did not include a specific case for the ObjectTypeAnnotation type in Flow definitions.
As a result, configuration options defined as Flow objects - such as:
auth: ?{ [string]: AuthAdapter };
were not mapped to the appropriate parser (objectParser) when generating CLI definitions.

This caused environment variables like PARSE_SERVER_AUTH_PROVIDERS to be treated as raw strings instead of being parsed as JSON objects.
In practice, this broke the built-in Microsoft authentication adapter (and any other adapter relying on object-type auth configs), throwing errors such as:
Error: Microsoft options are required.
The missing objectParser action in the generated definitions.js file prevented the environment variable from being correctly parsed into an object structure.

Approach

  • Updated the mapperFor function in buildConfigDefinitions.js to handle ObjectTypeAnnotation by mapping it to the objectParser, ensuring object types are parsed correctly.
  • Added the objectParser action to the auth option in ParseServerOptions in Definitions.js, enabling proper parsing of the auth configuration as an object.

Tasks

  • Add fix for ObjectTypeAnnotation handling in mapperFor
  • Regenerate CLI definitions
  • Add objectParser action for auth option
  • Add tests

Summary by CodeRabbit

  • Bug Fixes

    • Improved parsing of authentication provider configuration so JSON object inputs from environment variables are recognized and deserialized correctly, reducing errors when supplying nested provider settings.
  • Tests

    • Added unit tests validating type-to-parser mappings to ensure correct parser selection for various configuration input shapes.

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: add objectParser for ObjectTypeAnnotation (e.g. PARSE_SERVER_AUTH_PROVIDERS) fix: Add objectParser for ObjectTypeAnnotation (e.g. PARSE_SERVER_AUTH_PROVIDERS) Nov 7, 2025
@parse-github-assistant
Copy link

parse-github-assistant bot commented Nov 7, 2025

🚀 Thanks for opening this pull request!

@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

📝 Walkthrough

Walkthrough

Added ObjectTypeAnnotation handling to mapperFor (returning parsers.objectParser) and exported mapperFor. Also set ParseServerOptions.auth.action = parsers.objectParser and added unit tests validating type-annotation→parser mappings. No public function signatures changed.

Changes

Cohort / File(s) Summary
Build configuration
resources/buildConfigDefinitions.js
Added handling for ObjectTypeAnnotation in mapperFor to return parsers.objectParser. Also exported mapperFor via module.exports = { mapperFor } for testing.
Options definition
src/Options/Definitions.js
Set ParseServerOptions.auth.action to parsers.objectParser so PARSE_SERVER_AUTH_PROVIDERS is parsed as an object from environment input.
Tests
spec/buildConfigDefinitions.spec.js
New unit test file exercising mapperFor mappings for ObjectTypeAnnotation, AnyTypeAnnotation, ArrayTypeAnnotation, BooleanTypeAnnotation, NumberTypeAnnotation, and multiple GenericTypeAnnotation cases.

Sequence Diagram(s)

sequenceDiagram
  participant Env as Environment
  participant Mapper as buildConfigDefinitions.mapperFor
  participant Parsers as parsers
  participant Options as ParseServerOptions.auth

  note over Env,Mapper `#E8F6FF`: Build-time mapping of type annotations
  Env->>Mapper: Provide type annotation node (e.g., ObjectTypeAnnotation)
  alt ObjectTypeAnnotation
    Mapper-->>Parsers: map -> parsers.objectParser
  else AnyTypeAnnotation
    Mapper-->>Parsers: map -> parsers.anyParser
  else ArrayTypeAnnotation
    Mapper-->>Parsers: map -> parsers.arrayParser
  end
  Parsers-->>Options: set action = parsers.objectParser
  note over Parsers,Options `#E8F6FF`: Runtime env string → object via objectParser
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Small, localized logic change and one new test file.
  • Review attention:
    • Verify parsers is in scope where objectParser is referenced.
    • Confirm module.exports = { mapperFor } doesn't conflict with existing exports.
    • Validate tests accurately reflect expected AST shapes and expressions.

Possibly related issues

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: adding objectParser support for ObjectTypeAnnotation with a concrete example (PARSE_SERVER_AUTH_PROVIDERS).
Description check ✅ Passed The description includes the required issue link, a clear explanation of the problem and approach, and indicates that tests were added. However, the issue link format appears malformed.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Nov 7, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
resources/buildConfigDefinitions.js (1)

176-242: Consider adding ObjectTypeAnnotation handling for future-proofing.

The parseDefaultValue function handles various type annotations but doesn't include a case for ObjectTypeAnnotation. While this isn't currently an issue (since the auth option likely doesn't have a default value), adding this handling would make the function more complete and prevent potential issues if default values are added to object-type fields in the future.

Consider adding after line 214:

  } else if (t.isBooleanTypeAnnotation(elt)) {
    literalValue = t.booleanLiteral(parsers.booleanParser(value));
+ } else if (t.isObjectTypeAnnotation(elt)) {
+   const object = parsers.objectParser(value);
+   const props = Object.keys(object).map(key => {
+     const val = object[key];
+     if (typeof val === 'string') {
+       return t.objectProperty(t.identifier(key), t.stringLiteral(val));
+     } else if (typeof val === 'number') {
+       return t.objectProperty(t.identifier(key), t.numericLiteral(val));
+     } else if (typeof val === 'boolean') {
+       return t.objectProperty(t.identifier(key), t.booleanLiteral(val));
+     } else {
+       return t.objectProperty(t.identifier(key), t.identifier('undefined'));
+     }
+   });
+   literalValue = t.objectExpression(props);
  } else if (t.isGenericTypeAnnotation(elt)) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4124069 and 996205b.

📒 Files selected for processing (2)
  • resources/buildConfigDefinitions.js (1 hunks)
  • src/Options/Definitions.js (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-27T09:08:34.252Z
Learnt from: EmpiDev
Repo: parse-community/parse-server PR: 9770
File: src/triggers.js:446-454
Timestamp: 2025-08-27T09:08:34.252Z
Learning: When analyzing function signature changes in Parse Server codebase, verify that call sites are actually incorrect before flagging them. Passing tests are a strong indicator that function calls are already properly aligned with new signatures.

Applied to files:

  • src/Options/Definitions.js
🧬 Code graph analysis (1)
src/Options/Definitions.js (1)
resources/buildConfigDefinitions.js (1)
  • parsers (12-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Node 20
  • GitHub Check: Node 22
  • GitHub Check: MongoDB 6, ReplicaSet
  • GitHub Check: Node 18
  • GitHub Check: MongoDB 8, ReplicaSet
  • GitHub Check: PostgreSQL 16, PostGIS 3.5
  • GitHub Check: Redis Cache
  • GitHub Check: PostgreSQL 18, PostGIS 3.6
  • GitHub Check: MongoDB 7, ReplicaSet
  • GitHub Check: PostgreSQL 15, PostGIS 3.4
  • GitHub Check: PostgreSQL 17, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.3
  • GitHub Check: PostgreSQL 15, PostGIS 3.5
  • GitHub Check: Docker Build
🔇 Additional comments (2)
src/Options/Definitions.js (1)

110-115: LGTM! Generated code correctly adds objectParser action.

The addition of action: parsers.objectParser to the auth option is consistent with other object-type configuration options throughout this file (e.g., accountLockout, customPages, fileUpload). This ensures that the PARSE_SERVER_AUTH_PROVIDERS environment variable is properly parsed as a JSON object rather than treated as a raw string, which directly addresses the PR objective.

Note: This is generated code. The actual source changes are in src/Options/index.js and the generator script resources/buildConfigDefinitions.js.

resources/buildConfigDefinitions.js (1)

156-157: LGTM! ObjectTypeAnnotation handling correctly added.

The addition of ObjectTypeAnnotation handling in mapperFor is correct and consistent with the existing AnyTypeAnnotation handling. This ensures Flow object types (e.g., ?{ [string]: AuthAdapter }) are properly mapped to objectParser.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 7, 2025
@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.94%. Comparing base (133660f) to head (8224a93).

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #9912      +/-   ##
==========================================
- Coverage   93.07%   92.94%   -0.14%     
==========================================
  Files         187      188       +1     
  Lines       15224    15414     +190     
  Branches      177      177              
==========================================
+ Hits        14170    14326     +156     
- Misses       1042     1076      +34     
  Partials       12       12              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c72fff6 and 69875a2.

📒 Files selected for processing (1)
  • spec/buildConfigDefinitions.spec.js (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: For new Parse Server options, verify that the option is documented in src/Options/index.js and that npm run definitions has been executed to reflect changes in src/Options/docs.js and src/Options/Definitions.js. README.md documentation is a bonus but not required for new options.
🧬 Code graph analysis (1)
spec/buildConfigDefinitions.spec.js (1)
resources/buildConfigDefinitions.js (1)
  • wrap (148-148)
🔇 Additional comments (1)
spec/buildConfigDefinitions.spec.js (1)

40-185: Good test coverage for the new ObjectTypeAnnotation mapping.

The test suite provides comprehensive coverage of the mapperFor function, including the newly added ObjectTypeAnnotation mapping that this PR introduces. All major type annotation cases are covered.

However, please address the issues raised in previous comments regarding:

  1. Importing the actual implementation instead of recreating it locally
  2. Correcting the Babel AST structure access patterns
  3. Verifying the source of the name property

} else if (t.isObjectTypeAnnotation(elt)) {
return wrap(t.identifier('objectParser'));
} else if (t.isGenericTypeAnnotation(elt)) {
const type = elt.typeAnnotation.id.name;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix incorrect Babel AST path for GenericTypeAnnotation.

According to Babel AST specifications, GenericTypeAnnotation nodes have an id property directly, not nested under typeAnnotation. The correct access should be elt.id.name.

Apply this diff:

-        const type = elt.typeAnnotation.id.name;
+        const type = elt.id.name;

Additionally, update all test mock structures to match the correct Babel AST format. For example, at lines 104-108:

       const mockElement = {
         type: 'GenericTypeAnnotation',
-        typeAnnotation: {
-          id: {
-            name: 'Adapter',
-          },
+        id: {
+          name: 'Adapter',
         },
       };

Apply similar corrections to all GenericTypeAnnotation mocks in tests (lines 104-108, 121-125, 139-143, 156-160, 173-177).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const type = elt.typeAnnotation.id.name;
const type = elt.id.name;
🤖 Prompt for AI Agents
In spec/buildConfigDefinitions.spec.js around line 21, change usage of
elt.typeAnnotation.id.name to elt.id.name because GenericTypeAnnotation nodes
expose id directly; update the code accordingly and then update all test mock
AST structures to match Babel's GenericTypeAnnotation shape (replace nested
typeAnnotation.id with id) for the mocks at lines 104-108, 121-125, 139-143,
156-160, and 173-177 so the tests construct GenericTypeAnnotation nodes with an
id property that has a name.

@mattia1208
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69875a2 and 8224a93.

📒 Files selected for processing (2)
  • resources/buildConfigDefinitions.js (2 hunks)
  • spec/buildConfigDefinitions.spec.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • spec/buildConfigDefinitions.spec.js
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.
📚 Learning: 2025-11-08T13:46:04.940Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: For new Parse Server options, verify that the option is documented in src/Options/index.js and that npm run definitions has been executed to reflect changes in src/Options/docs.js and src/Options/Definitions.js. README.md documentation is a bonus but not required for new options.

Applied to files:

  • resources/buildConfigDefinitions.js
🔇 Additional comments (1)
resources/buildConfigDefinitions.js (1)

158-159: LGTM! ObjectTypeAnnotation handling correctly implemented.

The new handling for ObjectTypeAnnotation correctly maps Flow object types to objectParser, which fixes the issue where environment variables like PARSE_SERVER_AUTH_PROVIDERS were treated as raw strings. The implementation is consistent with the existing AnyTypeAnnotation handling and properly placed in the type-checking flow.

Comment on lines +386 to +388

// Export mapperFor for testing
module.exports = { mapperFor };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify that tests handle file system side effects.

Exporting mapperFor enables testing, which is good. However, when this module is required (e.g., by tests), it will execute the babel transformation at lines 378-385, which writes to Definitions.js and docs.js. Ensure that your test setup either:

  • Mocks the file system operations, or
  • Runs in an isolated environment where these writes are acceptable, or
  • Uses a test-specific entry point that only exports the function without running the build

🏁 Script executed:

#!/bin/bash
# Description: Check if tests mock fs operations or handle build side effects

# Look for test files that import buildConfigDefinitions
rg -n --type=js -A 5 "require.*buildConfigDefinitions|import.*buildConfigDefinitions"

# Check if tests mock fs.writeFileSync
rg -n --type=js -B 3 -A 3 "writeFileSync.*mock|mock.*writeFileSync|jest\.mock.*fs"

Length of output: 471



🏁 Script executed:

#!/bin/bash
# Get full context of buildConfigDefinitions.js around the export and transformation

echo "=== buildConfigDefinitions.js lines 370-390 ==="
sed -n '370,390p' resources/buildConfigDefinitions.js

echo ""
echo "=== Check if transformation is wrapped in conditionals ==="
sed -n '375,385p' resources/buildConfigDefinitions.js

echo ""
echo "=== Check test file setup/teardown ==="
head -40 spec/buildConfigDefinitions.spec.js

Length of output: 2399


🏁 Script executed:

#!/bin/bash
# Check for NODE_ENV or test environment conditions in buildConfigDefinitions.js

rg -n "process\.env|NODE_ENV|process\.argv" resources/buildConfigDefinitions.js

# Check if there's a test helper or setup file
fd -e "js" -path "*/spec/*" -name "*setup*|*helper*|*config*" 

Length of output: 168


🏁 Script executed:

#!/bin/bash
# Check if Jest is configured with setupFilesAfterEnv or similar that might mock fs

rg -n "jest|setupFiles|moduleNameMapper" jest.config.js package.json 2>/dev/null || echo "Config files not found in root, checking elsewhere"

# Look for jest configuration
fd -e "js" -o -e "json" -name "jest.config*" -o -name "package.json" -type f | head -5

Length of output: 167



🏁 Script executed:

#!/bin/bash
# Check if generated files are ignored or tracked

echo "=== Check .gitignore for src/Options/*.js ==="
grep -n "Options\|Definitions\|docs" .gitignore 2>/dev/null || echo "Pattern not found in .gitignore"

echo ""
echo "=== Check if generated files exist and their status ==="
ls -la src/Options/Definitions.js src/Options/docs.js 2>/dev/null || echo "Files not found (may not exist yet)"

echo ""
echo "=== Check if these files are versioned in git ==="
git ls-files src/Options/Definitions.js src/Options/docs.js 2>/dev/null || echo "Files not tracked"

Length of output: 372


🏁 Script executed:

#!/bin/bash
# Check if there's jest config at root or package.json jest config
cat package.json | grep -A 20 '"jest"' 2>/dev/null || echo "No jest config in package.json"

# Also try to find jest config files
find . -maxdepth 2 -name "jest.config.*" 2>/dev/null

Length of output: 30


🏁 Script executed:

#!/bin/bash
# Check if buildConfigDefinitions.js is only executed during build, not by tests
# Look for where buildConfigDefinitions.js is actually imported/used

rg -n "buildConfigDefinitions" --type=js -B 2 -A 2 | head -50

Length of output: 1499


Refactor to prevent file system writes during test import.

The side effect concern is confirmed: the transformation at lines 378-385 executes unconditionally on import, writing to versioned files src/Options/Definitions.js and src/Options/docs.js every time tests run.

Use one of these approaches:

  • Add if (require.main === module) guard around the transformation, so it only runs when executed directly
  • Add NODE_ENV === 'test' check to skip transformation during testing
  • Mock fs.writeFileSync in test setup
  • Create a separate test export that only exports mapperFor without running the build
🤖 Prompt for AI Agents
In resources/buildConfigDefinitions.js around lines 378–388, the unconditional
transformation/writes run on module import (causing file system writes during
tests); guard the transformation so it only runs when executed directly (e.g.,
wrap the write/transform block in if (require.main === module) or skip when
process.env.NODE_ENV === 'test'), leaving module.exports = { mapperFor } intact
so tests can import mapperFor without triggering any file writes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants